﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using AcademicPlanner.Domain.Models;

namespace AcademicPlanner.Presentation.Views.Shared
{
	/// <summary>
	/// Possible scenarios of a <c>AccountsForm</c> form.
	/// </summary>
	/// <version>1.0</version>
	/// <since>1.0</since>
	public enum AccountsFormScenario
	{
		FIRST_ACCOUNT,
		EDIT_ACCOUNTS
	}


	/// <summary>
	/// AccountsFormModel represents a model object for a <c>AccountsForm</c> form.
	/// </summary>
	/// <version>1.0</version>
	/// <since>1.0</since>
	public class AccountsFormModel : FormModel
	{
		/// <summary>
		/// Gets or sets the scenario to use the <c>AccountsForm</c> form under.
		/// </summary>
		/// <version>1.0</version>
		/// <since>1.0</since>
		public AccountsFormScenario Scenario { get; set; }

		/// <summary>
		/// Gets or sets the <c>Account</c>s whose data to save.
		/// </summary>
		/// <version>1.0</version>
		/// <since>1.0</since>
		public IList<Account> Accounts { get; set; }
	}


	/// <summary>
	/// AccountsForm represents a form to save data about a list of <c>Account</c>s.
	/// </summary>
	/// <seealso cref="T:SaveAccountsForm"/>
	/// <version>1.0</version>
	/// <since>1.0</since>
	public partial class AccountsForm : Form<AccountsFormModel>
	{
		/// <summary>
		/// Gets the model object for this form control.
		/// </summary>
		/// <version>1.0</version>
		/// <since>1.0</since>
		public new AccountsFormModel Model { get { return (AccountsFormModel)base.Model; } }

		/// <summary>
		/// Gets or sets the value of the user name field of this form; used in <c>FIRST_ACCOUNT</c> scenario.
		/// </summary>
		/// <version>1.0</version>
		/// <since>1.0</since>
		public string UserNameValue { get; set; }

		/// <summary>
		/// Gets or sets the value of the user password field of this form; used in <c>FIRST_ACCOUNT</c> scenario.
		/// </summary>
		/// <version>1.0</version>
		/// <since>1.0</since>
		public string UserPasswordValue { get; set; }


		/// <summary>
		/// Handles the load page event. This method initializes or customizes the form's properties
		/// based on the model object's <c>Scenario</c>.
		/// </summary>
		/// <param name="sender">The sender of the event.</param>
		/// <param name="e">The details of the event.</param>
		/// <version>1.0</version>
		/// <since>1.0</since>
		protected void Page_Load(object sender, EventArgs e)
		{
			method = FormMethod.Post;

			if (Model.Scenario.Equals(AccountsFormScenario.EDIT_ACCOUNTS))
			{
				//actionName = "Save";
				//controllerName = "People";
				//routeValues = new object { };
				//Name = "setupPersonForm";
				//SaveAccountsViewData = new ViewDataDictionary();
				//SaveAccountsViewData["IsSub"] = true;
				//SaveAccountsViewData["NamesPrefix"] = GetFieldName("Accounts");
			}
			else
			{
				actionName = "Setup";
				controllerName = "People";
				routeValues = new object { };
				Title = Tr("Account Information");
				Name = "saveFirstAccountForm";
				SubmitButtonValue = Tr("Save Account");
			}

			if (string.IsNullOrEmpty(Model.Id)) Model.Id = Name;

			if (Model.Scenario.Equals(AccountsFormScenario.EDIT_ACCOUNTS))
			{
				//EmailValue = Model.Person.Email;
				//NameValue = Model.Person.Name;
			}
			else
			{
				UserNameValue = "";
				UserPasswordValue = "";
			}
		}
	}
}